package edu.ynu.se.xiecheng.achitectureclass.controller;

import edu.ynu.se.xiecheng.achitectureclass.dto.SensorDataDTO;
import edu.ynu.se.xiecheng.achitectureclass.service.SensorDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/sensors")
public class SensorDataController {

    @Autowired
    private SensorDataService sensorDataService;

    @PostMapping("/fetch")
    public String fetchSensorData(@RequestParam String boxNo, @RequestParam List<String> sensorIds) {
        sensorDataService.fetchSensorData(boxNo, sensorIds);
        return "Sensor data fetched successfully.";
    }
    @GetMapping("/latest")
    public SensorDataDTO getLatestData() {
        return sensorDataService.getLatestData();
    }

    @GetMapping("/history/{sensorType}")
    public Page<?> getHistoricalData(
            @PathVariable String sensorType,
            @RequestParam(defaultValue = "0") int page,
            @RequestParam(defaultValue = "10") int size) {
            return sensorDataService.getHistoricalData(sensorType, page, size);
    }

}